'use client'

import { useState } from 'react'
import { Form, Input, Button, message } from 'antd'
import { useRouter } from 'next/navigation'
// import { post } from '@/api/base'

const SignIn = () => {
  const [form] = Form.useForm()
  const [isLoading, setIsLoading] = useState(false)
  const router = useRouter()

  const handleSubmit = async (values: { username: string; password: string }) => {
    setIsLoading(true)
    try {
      // 调用登录 API
      // const response = await post('/api/login', {
      //   body: JSON.stringify(values),
      // })
      // if (response.success) {
      //   // 登录成功，将 token 存入 cookie
      //   document.cookie = `token=${response.data.access_token}; path=/`
      //   message.success('登录成功')
      //   router.push('/dashboard')
      // } else {
      //   message.error(response.message)
      // }
      router.push('/dashboard')
    } catch (error) {
      message.error('登录失败，请稍后重试')
    } finally {
      setIsLoading(false)
    }
  }

  return (
    <div className='min-h-screen bg-gray-50 flex items-center justify-center p-4'>
      {/* <div className={`${styles['header-M5sNB3']}`}></div> */}
      <Form
        form={form}
        name='signin'
        layout='vertical'
        onFinish={handleSubmit}
        className='w-full max-w-md'>
        <h1 className='text-3xl font-bold text-center mb-8'>登录</h1>
        <Form.Item
          name='username'
          label='用户名'
          rules={[{ required: true, message: '请输入用户名' }]}>
          <Input placeholder='请输入用户名' />
        </Form.Item>
        <Form.Item
          name='password'
          label='密码'
          rules={[{ required: true, message: '请输入密码' }]}>
          <Input.Password placeholder='请输入密码' />
        </Form.Item>
        <Form.Item className='mt-4'>
          <Button
            type='primary'
            htmlType='submit'
            loading={isLoading}
            className='w-full'>
            {isLoading ? '登录中...' : '登录'}
          </Button>
        </Form.Item>
      </Form>
    </div>
  )
}

export default SignIn
